package com.hosever.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.hosever.core.AbstractModel;

/**
 * 文章
 * @author Sever
 *
 */
@Entity
@Table(name="tbl_article")
public class Article extends AbstractModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2176082570987823974L;
	
	/**
	 * 文章标题
	 */
	private String title;
	/**
	 * 文章内容
	 */
	@Column(name="content", columnDefinition="TEXT", nullable=true)
	private String content;
	/**
	 * 浏览数（热度）
	 */
	private int hot;
	/**
	 * 赞数
	 */
	private int praise;
	/**
	 * 评论数
	 */
	private int reviewNum;
	/**
	 * 是否置顶
	 */
	@Column(name="isTop", length=10,columnDefinition="int")
	private boolean isTop;
	/**
	 * 文章状态
	 * 0.无状态 1.被屏蔽
	 */
	private int status;
	/**
	 * 评论/回复
	 */
	@OneToMany(cascade=CascadeType.ALL,targetEntity=Review.class)
	@Fetch(FetchMode.JOIN)
	//updatable=false很关键，如果没有它，在级联删除的时候就会报错(反转的问题)
	@JoinColumn(name="ArticleId",updatable=false)
	@OrderBy("updateDate asc")
	private List<Review> reviews = new ArrayList<Review>();
	/**
	 * 所属标签
	 */
	@ManyToMany
	@JoinTable(
	name = "Article_Tag", 
	joinColumns ={@JoinColumn(name = "t_articleid") }, 
	inverseJoinColumns = {@JoinColumn(name = "t_tagid") 
	}) 
	private List<Tag> tags = new ArrayList<Tag>();
	
	public Article() {
		this.isTop=false;
	}
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public int getHot() {
		return hot;
	}
	public void setHot(int hot) {
		this.hot = hot;
	}
	public int getPraise() {
		return praise;
	}
	public void setPraise(int praise) {
		this.praise = praise;
	}
	public int getReviewNum() {
		return reviewNum;
	}
	public void setReviewNum(int reviewNum) {
		this.reviewNum = reviewNum;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public List<Review> getReviews() {
		return reviews;
	}
	public void setReviews(List<Review> reviews) {
		this.reviews = reviews;
	}
	public List<Tag> getTags() {
		return tags;
	}

	public void setTags(List<Tag> tags) {
		this.tags = tags;
	}
	public boolean isTop() {
		return isTop;
	}
	public void setTop(boolean isTop) {
		this.isTop = isTop;
	}
	
}
